package com.mach.platform.repository;

import com.mach.platform.domain.DMFConcentrationRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface DMFConcentrationRecordRepo extends BaseRepository<DMFConcentrationRecord> {

    @Query(value = "SELECT *,DATE_FORMAT(DMF_concentration_record_time,'%Y-%m-%d') as time FROM `DMF_concentration_record` where DMF_concentration_record_time between ?1 and ?2 GROUP BY time",
            countQuery = "select count(*) from (SELECT DATE_FORMAT(DMF_concentration_record_time,'%Y-%m-%d') as time FROM `DMF_concentration_record` where DMF_concentration_record_time between ?1 and ?2 GROUP BY time) as t",
    nativeQuery = true)
    Page<DMFConcentrationRecord> getListByTime(LocalDateTime ldtStartTime, LocalDateTime ldtEndTime, Pageable pageable);

    @Query(value = "select * from DMF_concentration_record where DATE_FORMAT(DMF_concentration_record_time,'%Y-%m-%d') = ?1 ORDER BY detection_time", nativeQuery = true)
    List<DMFConcentrationRecord> getProductionStateByTime(String time);
}
